package com.purong.purong.activity;

import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.QuestionBean;
import com.purong.purong.widget.JustifyTextView;

/**
 * Created by zengwenjie on 2017/12/6.
 */
public class HelpQuestDetActivity extends BaseActivity {
    private TextView questionTv;
//    private JustifyTextView answerTv;
    private WebView mWebView;
    private ProgressBar progressBar;
    private QuestionBean bean;
    @Override
    public int getRootViewId() {
        return R.layout.help_question_det;
    }

    @Override
    public void initBundle() {
        bean=(QuestionBean)getIntent().getSerializableExtra("QUESTION");
    }

    @Override
    public void initView() {
        showBack();
        showTitle("问题");
        questionTv=(TextView)findViewById(R.id.question);
        mWebView=(WebView)findViewById(R.id.web_view);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        mWebView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                progressBar.setVisibility(View.GONE);
            }
        });
        mWebView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                // TODO 自动生成的方法存根
                Log.e("zwj","..p="+newProgress);
                if(newProgress==100){
                    progressBar.setVisibility(View.GONE);//加载完网页进度条消失
                }
                else{
                    progressBar.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
                    progressBar.setProgress(newProgress);//设置进度值
                }

            }
        });
        progressBar=(ProgressBar)findViewById(R.id.progress_bar);
//        answerTv=(JustifyTextView)findViewById(R.id.answer);
    }

    @Override
    public void initData() {
        if (bean!=null){
            if (bean.getQuestion_content()!=null){
                int p=bean.getQuestion_content().lastIndexOf("\\n");
                if (p!=-1){
                    questionTv.setText(bean.getQuestion_content().substring(0,p));
                }else {
                    questionTv.setText(bean.getQuestion_content());
                }
            }


            mWebView.loadDataWithBaseURL(null,bean.getReply_content(),"text/html", "UTF-8",null);
        }
    }
}
